home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12999 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  52 lines

  1. Path: ucl.ac.uk!nobody
  2. From: ucecb09@ucl.ac.uk (Robert Byrne)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: mixing static and const qualifiers for class members
  5. Date: Wed, 20 Mar 1996 14:37:49 GMT
  6. Organization: University College London
  7. Message-ID: <1996Mar20.143749.90333@ucl.ac.uk>
  8. NNTP-Posting-Host: crs4gw.crs4.it
  9. Originator: daemon@crs4gw.crs4.it
  10.  
  11. Paulo Eduardo Neves <neves@lmf-di.puc-rio.br> writes:
  12.  
  13. >James Youngman wrote:
  14. >> 
  15. >> class Foo
  16. >> {
  17. >>         static const int nPositions = 6;
  18. >>         int nData[nPositions];
  19. >> }
  20. >> 
  21. >> ...how is this done?
  22.  
  23. >class Foo {
  24. >  static const int nPositions;
  25. >};
  26.  
  27. >const int Foo::nPositions = 6;
  28.  
  29. >You also won't be able to declare the array this way, since nPosition
  30.  
  31. >class Foo {
  32. >  Foo():nData(new int[nPositions]){}
  33. >  static const int nPositions;
  34. >  int *nData;
  35. >};
  36.  
  37. The simple way to declare integral class constants is with an enumeration.
  38.  
  39. class Foo{
  40.     enum constants{nPositions = 6};
  41.     public:
  42.     int nData[nPositions];
  43. };
  44.  
  45.  
  46. Rob
  47.  
  48. --
  49. Robert Byrne         `I think therefore I am' says rather more than
  50. ucecb09@ucl.ac.uk     is strictly certain.'       -Bertrand Russell
  51.  
  52.